//
//  GM_CLASSObjectController.swift
//  SWIFT_LEARN
//
//  Created by youxin on 2018/1/16.
//  Copyright © 2018年 YST. All rights reserved.
//

import UIKit

class GM_CLASSObjectController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let shre = Share()
        let ss = shre.simpleDescription()
        print(ss)
        // 类的创建
        var shape = Share() // 这就是默认的构造方法
        shape.numberOfSides = 6 // 调用类中的属性
        var shapeDescription = shape.simpleDescription()
        print(shapeDescription)
        print(shape.areaDescription())
        
        
        //子类继承父类 调用
        let square = wjSquare(sideLength: 4.0, name: "square")
        square.wjArea()
        square.wjDescription()
        
        
        //构造器(initializers)
// 在swift中创建新的实例会使用到关键字init。
 //       init() {
//            // do somethings
//        }
        
    
        let f = Fahrenheit()
        print("The default temperature is \(f.temperature)° Fahrenheit")
        // Prints "The default temperature is 32.0° Fahrenheit”
        
//        Swift 采用以下三条规则来限制构造器之间的代理调用
//        规则 1 指定构造器必须调用其直接父类的的指定构造器。
//        规则 2 便利构造器必须调用同一类中定义的其它构造器。
//        规则 3 便利构造器必须最终导致一个指定构造器被调用。
//        也就是：
//            • 指定构造器必须总是向上代理
//            • 便利构造器必须总是横向代理
   
    }
    
    //构造
    struct Fahrenheit {
        var temperature: Double
        init() {
            temperature = 32.0
        }
    }
    //枚举
    enum pocker : Int {
        case ace = 1
        case two, three, four, five, six, seven, eight, nine, ten
        case jack, queen, king
        func wjPockerDescription() -> String {
            switch self {
            case .ace:
                return "ace"
            case .jack:
                return "jack"
            case .queen:
                return "queen"
            case .king:
                return "king"
            default:
                return String(self.rawValue)
            }
        }
    }
 
    
    // 子类继承父类   wjSquare 继承  wjNamedShape
    class wjSquare : wjNamedShape {
        var sideLength : Double
        init(sideLength : Double, name : String) {
            self.sideLength = sideLength // 这里需要注明的是在调用父类的初始化方法之前，所有的属性必要赋值或者说是有一个初始值。
            super.init(name: name)
            numberOfSides = 4
        }
        
        func wjArea() -> Double {
            return sideLength * sideLength
        }
        
        // 重写父类的方法必须要加上override关键字
        override func wjDescription() -> String {
            return "a square with side length of \(sideLength), and area is \(wjArea()) squaremeter"
        }
    }

    
    // 带有初始化方法的类的创建
    class wjNamedShape {
        var numberOfSides = 0
        var name : String
        init(name : String) { // 这是官方文档说的designated initializer
            self.name = name
        }
        func wjDescription() -> String {
            return "a shape with \(numberOfSides) sides"
        }
    }

    // 类的创建
    class Share {
        // 相当于是这个类的属性
        var numberOfSides = 0
        func simpleDescription() -> String {
            return "a shape with \(numberOfSides) sides"
        }
        let area = 1
        func areaDescription() -> String {
            return "a shape area is \(area) squaremeter"
        }
        // 这个类中没有本个类的初始化方法，
    }
    
   

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
